package com.ls.product.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ls.common.entity.PageData;
import com.ls.product.mapper.ProductMapper;
import com.ls.product.pojo.dto.PageProductDTO;
import com.ls.product.service.IProductService;
import org.springframework.stereotype.Service;
import com.ls.product.pojo.entity.Product;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaotang
 * @since 2023-04-07
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements IProductService {

    @Override
    public int updateStock(Integer id) {
        return baseMapper.updateStock(id);
    }

    @Override
    public PageData<Product> listPageProducts(PageProductDTO pageProductDTO) {
        IPage<Product> page = new Page<>(pageProductDTO.getCurrentPage(), pageProductDTO.getPageSize());
        IPage<Product> ipage = baseMapper.listPageProducts(page, pageProductDTO);
        return new PageData<>(ipage.getTotal(), ipage.getRecords());
    }
}
